package cn.yunyichina.provider.order.service.impl;

import cn.yunyichina.provider.iface.entity.order.OrderRegSchedulerVo;
import cn.yunyichina.provider.order.dao.OrderRegSchedulerDao;
import cn.yunyichina.provider.order.entity.OrderRegScheduler;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 挂号订单定时任务
 * Created by Administrator on 2017/5/17.
 */
@Service
public class OrderRegSchedulerServiceImpl {

    @Autowired
    OrderRegSchedulerDao dao;

    public void addOrderRegScheduler(OrderRegSchedulerVo vo) {
        OrderRegScheduler order = new OrderRegScheduler();
        BeanUtils.copyProperties(vo,order);
        dao.insert(order);
    }

    public void updateOrderRegScheduler(OrderRegSchedulerVo vo) {
        OrderRegScheduler order = new OrderRegScheduler();
        BeanUtils.copyProperties(vo,order);
        dao.update(order);
    }

    public OrderRegSchedulerVo selectOrderRegSchedulerById(String id) {
        OrderRegScheduler order = dao.selectById(id);
        if(order == null){
            return null;
        }
        OrderRegSchedulerVo vo = new OrderRegSchedulerVo();
        BeanUtils.copyProperties(order,vo);
        return vo;
    }

    public List<OrderRegSchedulerVo> findOrderRegScheduler(OrderRegSchedulerVo vo) {
        OrderRegScheduler order = new OrderRegScheduler();
        BeanUtils.copyProperties(vo,order);
        List<OrderRegScheduler> list = dao.select(order);
        if(!CollectionUtils.isEmpty(list)){
            List<OrderRegSchedulerVo> outList = new ArrayList<>();
            for(OrderRegScheduler orderS:list){
                OrderRegSchedulerVo out = new OrderRegSchedulerVo();
                BeanUtils.copyProperties(orderS,out);
                outList.add(out);
            }
            return outList;
        }
        return null;
    }
}
